//
//  SEGActivityDetailToolBarView.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 2017/8/1.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGActivityDetailToolBarView.h"
#import <SEGPlatform/SEGAdjustableButton.h>
#import "SEGBasicBussinessCommonDefine.h"
#import "SEGAlertView.h"
#import "SEGPlatformManager.h"

static CGFloat leftButtonWidth = 125.0;

@interface SEGActivityDetailToolBarView ()<UITextViewDelegate>
/**
 正常界面背景
 */
@property (nonatomic, strong)UIView *normalBgView;

/**
 输入界面背景
 */
@property (nonatomic, strong)UIView *commentBgView;

/**
 点赞按钮
 */
@property (nonatomic, strong)SEGAdjustableButton *praiseButton;
/**
 评论按钮
 */
@property (nonatomic, strong)SEGAdjustableButton *commentButton;

/**
 活动状态
 */
@property (nonatomic, assign) SEGActivityStatus activityStatus;

/**
 线下活动报名审核状态
 */
@property (nonatomic, assign) SEGActivityApplyAuditStatus applyAuditStatus;

/**
  是否为邻里圈工具栏
  */
@property (nonatomic, assign) BOOL isNeighboorhood;
/** 键盘弹起定时器 */
@property (nonatomic, strong) NSTimer *timer;

@end

@implementation SEGActivityDetailToolBarView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self customUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self customUI];
    }
    return self;
}

- (void)customUI
{
    self.backgroundColor = kColor_TABLE;
}

/**
 * 设置 新邻里圈详情 界面底部工具栏
 * @param type 类型
 * @param isMyMarket 是否是我自己的集市
 */
- (void)hlb_setUpViewWithOperationType:(SEGNeighbourhoodOperationType)type
                            isMyMarket:(BOOL)isMyMarket
                          commentCount:(NSString *)commentCount
                              isLikeed:(BOOL)isLikeed
                             likeCount:(NSString *)likeCount {
    self.isNeighboorhood = YES;
    //为了防止重复添加点击事件，先移除之前所有的
    [self.publicButton removeTarget:self
                             action:NULL
                   forControlEvents:UIControlEventTouchUpInside];
    if (type == SEGNeighbourhoodOperationType_Market && !isMyMarket) { // 非自己发的集市
        [self seg_setUpViewWithThreeButton];
        // 联系
        [self.publicButton setBackgroundImage:[UIImage imageWithColor:kColor_T] forState:UIControlStateNormal];
        [self.publicButton setTitle:@"立即联系" forState:UIControlStateNormal];
        [self.publicButton addTarget:self
                              action:@selector(seg_connectButtonPressed)
                    forControlEvents:UIControlEventTouchUpInside];
    } else {
        [self seg_setUpViewWithCommentPraiseButton];
    }
    // 留言
    self.commentButton.titleLabel.font = kFont_13;
    [self.commentButton setTitleColor:kColor_1 forState:UIControlStateNormal];
    [self.commentButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_tab_pinlun_hlb")] forState:UIControlStateNormal];
    if ([commentCount integerValue] > 0) {
        [self.commentButton setTitle:[NSString stringWithFormat:@"%@",commentCount] forState:UIControlStateNormal];
    }else {
        [self.commentButton setTitle:@"评论" forState:UIControlStateNormal];
    }
    [self.commentButton layoutButtonWithEdgeInsetsStyle:SEGButtonEdgeInsetsStyleLeft imageTitleSpace:5];
    // 点赞
    self.praiseButton.selected = isLikeed;
    self.praiseButton.titleLabel.font = kFont_13;
    [self.praiseButton setTitleColor:kColor_1 forState:UIControlStateNormal];
    [self.praiseButton setTitleColor:kColor_T forState:UIControlStateDisabled];
    [self.praiseButton setTitleColor:kColor_T forState:UIControlStateSelected];
    [self.praiseButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_tab_zan_hlb")] forState:UIControlStateNormal];
    [self.praiseButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_huati_zan_gray_pre")] forState:UIControlStateDisabled];
    [self.praiseButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_huati_zan_gray_pre")] forState:UIControlStateSelected];
    if ([likeCount integerValue] > 0) {
        [self.praiseButton setTitle:[NSString stringWithFormat:@"%@",likeCount] forState:UIControlStateNormal];
    } else {
        [self.praiseButton setTitle:@"点赞" forState:UIControlStateNormal];
    }
    [self.praiseButton layoutButtonWithEdgeInsetsStyle:SEGButtonEdgeInsetsStyleLeft imageTitleSpace:5];
    if (self.commentBgView.hidden == NO) {
        [self bringSubviewToFront:self.commentBgView];
    }
}

/**
 * 设置邻里圈界面底部工具栏
 * @author Wendy
 * @param type 类型
 * @param isMyMarket 是否是我自己的集市
 */
- (void)setUpViewWithOperationType:(SEGNeighbourhoodOperationType)type isMyMarket:(BOOL)isMyMarket isLikeed:(BOOL)isLikeed likeCount:(NSString *)likeCount
{
    self.isNeighboorhood = YES;
    //为了防止重复添加点击事件，先移除之前所有的
    [self.publicButton removeTarget:self action:NULL forControlEvents:UIControlEventTouchUpInside];
    
    self.commentButton.hidden = NO;
    self.commentButton.titleLabel.font = kFont_16;
    [self.commentButton setTitleColor:kColor_1 forState:UIControlStateNormal];
    [self.commentButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_bottom_comment")] forState:UIControlStateNormal];

    self.praiseButton.titleLabel.font = kFont_16;
    [self.praiseButton setTitleColor:kColor_1 forState:UIControlStateNormal];
    [self.praiseButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_bottom_zan")] forState:UIControlStateNormal];
    [self.praiseButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_huati_zan_gray_pre")] forState:UIControlStateDisabled];
    [self.praiseButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_huati_zan_gray_pre")] forState:UIControlStateSelected];
    
    [self.publicButton setTitleColor:kColor_1 forState:UIControlStateNormal];
    [self.publicButton setBackgroundImage:[UIImage imageWithColor:kColor_W] forState:UIControlStateNormal];
    [self.publicButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_bottom_contact")] forState:UIControlStateNormal];
    [self.publicButton setTitle:@"联系TA" forState:UIControlStateNormal];
    [self.publicButton layoutButtonWithEdgeInsetsStyle:SEGButtonEdgeInsetsStyleLeft imageTitleSpace:5];
    [self.publicButton addTarget:self action:@selector(seg_connectButtonPressed) forControlEvents:UIControlEventTouchUpInside];

    if (type == SEGNeighbourhoodOperationType_Market) {//集市不显示点赞按钮
        self.praiseButton.hidden = YES;

        if (!isMyMarket) {
            self.publicButton.hidden = NO;

            [self.commentButton mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(leftButtonWidth);
                make.top.equalTo(self.normalBgView);
                make.left.equalTo(self.normalBgView);
                make.height.equalTo(self.normalBgView);
            }];
            
            //分割竖线
            UIView *sepreateLine = [[UIView alloc] init];
            sepreateLine.backgroundColor = kColor_L2;
            [self.normalBgView addSubview:sepreateLine];
            [sepreateLine mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.commentButton.mas_right);
                make.centerY.equalTo(self.normalBgView);
                make.height.mas_equalTo(25);
                make.width.mas_equalTo(0.5);
            }];
            
            [self.publicButton mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(sepreateLine.mas_right);
                make.top.equalTo(self.normalBgView).offset(0.5);
                make.right.equalTo(self.normalBgView);
                make.bottom.equalTo(self.normalBgView).offset(-0.5);
            }];
        }else {
            //自己发布的集市只显示评论按钮
            self.publicButton.hidden = YES;
            [self.commentButton mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.width.equalTo(self.normalBgView);
                make.top.equalTo(self.normalBgView);
                make.left.equalTo(self.normalBgView);
                make.height.equalTo(self.normalBgView);
            }];
        }
    }else {
        self.publicButton.hidden = YES;
        self.praiseButton.hidden = NO;
        self.commentButton.hidden = NO;
        [self.praiseButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(leftButtonWidth);
            make.top.equalTo(self.normalBgView);
            make.left.equalTo(self.normalBgView);
            make.height.equalTo(self.normalBgView);
        }];
        
        //分割竖线
        UIView *sepreateLine = [[UIView alloc] init];
        sepreateLine.backgroundColor = kColor_L2;
        [self.normalBgView addSubview:sepreateLine];
        [sepreateLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.praiseButton.mas_right);
            make.centerY.equalTo(self.normalBgView);
            make.height.mas_equalTo(25);
            make.width.mas_equalTo(0.5);
        }];
        
        [self.commentButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(sepreateLine.mas_right);
            make.top.equalTo(self.normalBgView);
            make.right.equalTo(self.normalBgView);
            make.height.equalTo(self.normalBgView);
        }];
        
        if (isLikeed) {
            self.praiseButton.selected = YES;
            [self.praiseButton setTitle:[NSString stringWithFormat:@"%@个赞",likeCount] forState:UIControlStateNormal];
            [self.praiseButton layoutButtonWithEdgeInsetsStyle:SEGButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        }else {
            self.praiseButton.selected = NO;
            if ([likeCount integerValue] > 0) {
                [self.praiseButton setTitle:[NSString stringWithFormat:@"%@个赞",likeCount] forState:UIControlStateNormal];
            }else {
                [self.praiseButton setTitle:@"点赞" forState:UIControlStateNormal];
            }
            [self.praiseButton layoutButtonWithEdgeInsetsStyle:SEGButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        }
    }
    if (self.commentBgView.hidden == NO) {
        [self bringSubviewToFront:self.commentBgView];
    }
}

/**
 * 设置界面
 * @author Wendy
 * @param type 活动类型
 */
- (void)setUpViewWithType:(SEGActivityType)type status:(SEGActivityStatus)status isReview:(BOOL)isReview isLikeed:(BOOL)isLikeed likeCount:(NSString *)likeCount triggerEvent:(NSString *)triggerEvent {
    [self setupViewWithType:type status:status isReview:isReview isLikeed:isLikeed likeCount:likeCount commentCount:@"0" triggerEvent:triggerEvent];
}


/// 设置底部工具栏样式（活动底部）
/// @param type 活动类型
/// @param status 活动状态
/// @param isReview isReview
/// @param isLikeed 是否点赞
/// @param likeCount 点赞个数
/// @param commentCount 评论个数
/// @param triggerEvent 事件
- (void)setupViewWithType:(SEGActivityType)type
                   status:(SEGActivityStatus)status
                 isReview:(BOOL)isReview
                 isLikeed:(BOOL)isLikeed
                likeCount:(NSString *)likeCount
             commentCount:(NSString *)commentCount
             triggerEvent:(NSString *)triggerEvent
{
    //为了防止重复添加点击事件，先移除之前所有的
    [self.publicButton removeTarget:self action:NULL forControlEvents:UIControlEventTouchUpInside];
    switch (type) {//活动类型(1:征集类,2:抽奖类,3:投票类,4:调查类,5:线下类,6:签到类,7:触发类)
        case SEGActivityType_Collect: /*征集类*/
        {
            if (isReview) {//开启留言板
                [self seg_setUpViewWithThreeButton];
            }else {
                [self seg_setUpViewWithTwoButton];
            }
            [self.publicButton setTitle:@"我要参加" forState:UIControlStateNormal];
            [self.publicButton addTarget:self action:@selector(seg_uploadButtonPressed) forControlEvents:UIControlEventTouchUpInside];
            break;
        }
        case SEGActivityType_Lottery: /*抽奖类 只有点赞和评论*/
        {
            if (isReview) {//开启留言板
                [self seg_setUpViewWithCommentPraiseButton];
            }else {
//                [self seg_setUpViewWithOneButton];
            }
            break;
        }
        case SEGActivityType_OffLine: /*线下类*/
        {
            if (isReview) {//开启留言板
                [self seg_setUpViewWithThreeButton];
            }else {
                [self seg_setUpViewWithTwoButton];
            }
//            [self.publicButton setTitle:@"我要报名" forState:UIControlStateNormal];
            [self changePublicButtonByApplyAuditStatus:self.applyAuditStatus];
            [self.publicButton addTarget:self action:@selector(seg_applyButtonPressed) forControlEvents:UIControlEventTouchUpInside];
            break;
        }
        case SEGActivityType_Sign: /*签到类 没有底部工具栏*/
        {
            break;
        }
        case SEGActivityType_Trigger: /*触发类*/
        {
         if([triggerEvent isEqualToString:@"payManagementFee"]) {//物业缴费 不显示我要参加按钮
             if (isReview) {//开启留言板
                 [self seg_setUpViewWithCommentPraiseButton];
             }else {
//                 [self seg_setUpViewWithOneButton];
             }
         }else {
             if (isReview) {//开启留言板
                 [self seg_setUpViewWithThreeButton];
             }else {
                 [self seg_setUpViewWithTwoButton];
             }
             [self.publicButton setTitle:@"我要参加" forState:UIControlStateNormal];
         }
            [self.publicButton addTarget:self action:@selector(seg_attendButtonPressed) forControlEvents:UIControlEventTouchUpInside];
            break;
        }
    }
    
    // 设置点赞数量
    self.praiseButton.enabled = !isLikeed; // 点赞过的不能再点击
    NSString *defalutPraiseText = @"点赞";
    [self.praiseButton setTitle:defalutPraiseText forState:UIControlStateNormal];
    if (likeCount && [likeCount integerValue] > 0) {
        NSString *praiseDisplayText = likeCount;
        praiseDisplayText = [NSString stringWithFormat:@"%@个赞",likeCount];
        [self.praiseButton setTitle:praiseDisplayText forState:UIControlStateNormal];
    }
    [self.praiseButton layoutButtonWithEdgeInsetsStyle:SEGButtonEdgeInsetsStyleLeft imageTitleSpace:5];
 
    
    // 设置活动状态
    self.activityStatus = status;
    if (self.activityStatus == SEGActivityStatus_NotBegin) {
        [self.publicButton setTitle:@"活动未开始" forState:UIControlStateNormal];
        self.publicButton.enabled = NO;
    }else if (self.activityStatus == SEGActivityStatus_Over) {
        [self.publicButton setTitle:@"活动已结束" forState:UIControlStateNormal];
        self.publicButton.enabled = NO;
    }
}

//显示评论界面
- (void)showCommentView {
    [self showCommentViewWithPlaceholder:activityToolBarDefalutDesc];
}

/**
 显示评论界面
 @param placeholder 占位文字
 */
- (void)showCommentViewWithPlaceholder:(NSString *)placeholder {
    self.commentBgView.hidden = NO;
    self.describeLabel.text = placeholder;
    [self bringSubviewToFront:self.commentBgView];
    if (!self.alwaysShowCommentView) {
        NSTimeInterval interval = 0.1;
        self.timer = [NSTimer timerWithTimeInterval:interval target:self selector:@selector(showKeyboard) userInfo:nil repeats:NO];
        [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
    }
}
- (void)showKeyboard {
    [self.textView becomeFirstResponder];
    if (self.timer) {
        [self.timer invalidate];
        self.timer = nil;
    }
}
- (void)hiddenCommentView {
    self.commentBgView.hidden = YES;
    [self sendSubviewToBack:self.commentBgView];
    if (self.timer) {
        [self.timer invalidate];
        self.timer = nil;
    }
    [self.textView resignFirstResponder];
}

/**
 * 线下活动根据报名审核状态修改按钮UI
 * @author Wendy
 * @param applyAuditStatus 报名审核状态
 */
- (void)changePublicButtonByApplyAuditStatus:(SEGActivityApplyAuditStatus)applyAuditStatus
{
    self.applyAuditStatus = applyAuditStatus;
    switch (applyAuditStatus) {//1:报名未审核 2:报名审核通过 4:可以报名 5:报名时间结束
        case SEGActivityApplyAuditStatus_NotAudit:
        {
            [self.publicButton setTitle:@"审核中" forState:UIControlStateNormal];
            self.publicButton.enabled = NO;
            break;
        }
        case SEGActivityApplyAuditStatus_Pass:
        {
            [self.publicButton setTitle:@"报名成功" forState:UIControlStateNormal];
            self.publicButton.enabled = NO;
            break;
        }
        case SEGActivityApplyAuditStatus_CanApply:
        {
 
            [self.publicButton setTitle:@"我要报名" forState:UIControlStateNormal];
            [self.publicButton setBackgroundImage:[UIImage imageWithColor:kColor_T] forState:UIControlStateNormal];
            self.publicButton.enabled = YES;
            break;
        }
        case SEGActivityApplyAuditStatus_TimeOver:
        {
            [self.publicButton setTitle:@"报名结束" forState:UIControlStateNormal];
            self.publicButton.enabled = NO;
            break;
        }
            
        default:
            break;
    }
}

#pragma mark - 私有方法
//三个按钮 评论 点赞 上传
- (void)seg_setUpViewWithThreeButton
{
    self.commentButton.hidden = NO;
    [self.commentButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.normalBgView).dividedBy(4);
    }];
    
    //分割竖线
    UIView *sepreateLine = [[UIView alloc] init];
    sepreateLine.backgroundColor = kColor_L2;
    [self.normalBgView addSubview:sepreateLine];
    [sepreateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.commentButton.mas_right);
        make.centerY.equalTo(self.normalBgView);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(0.5);
    }];
 
    [self.praiseButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.normalBgView).dividedBy(4);
    }];
    
    [self.publicButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.normalBgView).dividedBy(2);
    }];
 
}

//两个按钮 点赞 上传／
- (void)seg_setUpViewWithTwoButton
{
    self.commentButton.hidden = YES;
 
    [self.praiseButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.normalBgView).dividedBy(4);
    }];
    
    [self.publicButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.normalBgView).multipliedBy(3.0 / 4.0);
    }];
 }

//评论和点赞两个按钮
- (void)seg_setUpViewWithCommentPraiseButton
{
    self.commentButton.hidden = NO;
    [self.commentButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.normalBgView).dividedBy(2);
    }];
    
    //分割竖线
    UIView *sepreateLine = [[UIView alloc] init];
    sepreateLine.backgroundColor = kColor_L2;
    [self.normalBgView addSubview:sepreateLine];
    [sepreateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.commentButton.mas_right);
        make.centerY.equalTo(self.normalBgView);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(0.5);
    }];
    
    [self.praiseButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.normalBgView).dividedBy(2);
    }];
    self.publicButton.hidden = YES;
}

#pragma mark - UITextViewDelegate
- (void)textViewDidChange:(UITextView*)textView
{
    if ([[textView text] length] > 0) {
        [self.describeLabel setHidden:YES];
    }
    else {
        [self.describeLabel setHidden:NO];
    }
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text {
    if ([text isEqualToString:@"\n"]) {//判断输入的字是否是回车，即按下return
        [textView resignFirstResponder];
        [self seg_sendButtonPressed];
        return NO;
    }
    return YES;
}

- (void)seg_commentButtonPressed
{
    if (self.activityStatus == SEGActivityStatus_NotBegin) {
        [SEGAlertView showTmepMessageWithMessage:@"亲！活动还未开始，请稍后再试哦！"];
    }else if (self.activityStatus == SEGActivityStatus_Over) {
        [SEGAlertView showTmepMessageWithMessage:@"亲，活动已结束，下次早点来吧！"];
    }else {
        // 不在活动页面上才显示键盘，否则会导致失焦
        if (!self.isFromActivity) {
            [self showCommentView];
        }
        if (self.delegate && [self.delegate respondsToSelector:@selector(activityShouldShowInputView:)]) {
            [self.delegate activityShouldShowInputView:YES];
        }
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(shouldShowInputView:)]) {
            [self.delegate shouldShowInputView:YES];
        }
        if (self.isNeighboorhood) {
            if (self.delegate && [self.delegate respondsToSelector:@selector(commentButtonClicked)]) {
                [self.delegate commentButtonClicked];
            }
        }
    }
}

- (void)seg_sendButtonPressed
{
    // 提交的时候 去掉前后空格和回车
    NSString *content = self.textView.text;
    //如果仅仅是去前后空格，用whitespaceCharacterSet
    NSCharacterSet  *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    self.textView.text = [content stringByTrimmingCharactersInSet:set];
    if (self.textView.text.length == 0) {
        [SEGAlertView showTmepMessageWithMessage:@"请填写评论内容"];
        return;
    }
    if (self.textView.text.length < 2) {
        [SEGAlertView showTmepMessageWithMessage:@"输入内容不能少于2个字。"];
        return;
    }
    if (self.textView.text.length > 140) {
        [SEGAlertView showTmepMessageWithMessage:@"亲，您输入的内容已超过140字。"];
        return;
    }
    
    if (!self.alwaysShowCommentView) {//改变视图样式
        self.commentBgView.hidden = YES;
        [self sendSubviewToBack:self.commentBgView];
        if (self.delegate && [self.delegate respondsToSelector:@selector(shouldShowInputView:)]) {
            [self.delegate shouldShowInputView:NO];
        }
    }
    if (self.delegate && [self.delegate respondsToSelector:@selector(sendButtonActionWithContent:)]) {
        [self.delegate sendButtonActionWithContent:self.textView.text];
        self.textView.text = @"";
        [self.describeLabel setHidden:NO];
    }
}

- (void)seg_praiseButtonPressed
{
    if (self.activityStatus == SEGActivityStatus_NotBegin) {
        [SEGAlertView showTmepMessageWithMessage:@"亲！活动还未开始，请稍后再试哦！"];
    }else if (self.activityStatus == SEGActivityStatus_Over) {
        [SEGAlertView showTmepMessageWithMessage:@"亲，活动已结束，下次早点来吧！"];
    }else {
        if (self.delegate && [self.delegate respondsToSelector:@selector(praiseButtonAction)]) {
            [self.delegate praiseButtonAction];
        }
    }
}

//上传作品
- (void)seg_uploadButtonPressed
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(uploadButtonAction)]) {
        [self.delegate uploadButtonAction];
    }
}

//我要报名
- (void)seg_applyButtonPressed
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(applyButtonAction)]) {
        [self.delegate applyButtonAction];
    }
}

//我要参加
- (void)seg_attendButtonPressed
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(attendButtonAction)]) {
        [self.delegate attendButtonAction];
    }
}

//联系TA
- (void)seg_connectButtonPressed
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(connectButtonAction)]) {
        [self.delegate connectButtonAction];
    }
}

#pragma mark - traitCollectionDidChange
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
    [super traitCollectionDidChange:previousTraitCollection];
    
    if (self.publicButton.currentImage) {
        [self.publicButton setImage:[UIImage imageWithContentsOfFile:self.publicButton.currentImage.anyNamePath] forState:self.publicButton.state];
    }
    
    if (self.commentButton.currentImage) {
        [self.commentButton setImage:[UIImage imageWithContentsOfFile:self.commentButton.currentImage.anyNamePath] forState:self.commentButton.state];
    }
    
    if (self.praiseButton.currentImage) {
        [self.praiseButton setImage:[UIImage imageWithContentsOfFile:self.praiseButton.currentImage.anyNamePath] forState:self.praiseButton.state];
    }
    
    
}

#pragma mark - getter
- (UIView *)normalBgView {
    if (!_normalBgView) {
        CGRect rect = CGRectMake(0, 0, kScreenWidth, activityToolBarNormalHeight);
        _normalBgView = [[UIView alloc] initWithFrame:rect];
        _normalBgView.backgroundColor = kColor_W;
        [self addSubview:_normalBgView];
 
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 0.5)];
        line.backgroundColor = kColor_L2;
        [_normalBgView addSubview:line];
        UIView *bottom_line = [[UIView alloc] initWithFrame:CGRectMake(0, _normalBgView.height-0.5, kScreenWidth, 0.5)];
        bottom_line.backgroundColor = kColor_L2;
        [_normalBgView addSubview:bottom_line];
     }
    return _normalBgView;
}

- (SEGAdjustableButton *)commentButton
{
    if (!_commentButton) {
        //评论按钮
        _commentButton = [[SEGAdjustableButton alloc] init];
        [_commentButton setTitle:@"评论" forState:UIControlStateNormal];
        [_commentButton setTitleColor:kColor_2 forState:UIControlStateNormal];
        [_commentButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_comment")] forState:UIControlStateNormal];
        _commentButton.titleLabel.font = kFont_10;
        [_commentButton addTarget:self action:@selector(seg_commentButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [self.normalBgView addSubview:_commentButton];
        [_commentButton layoutButtonWithEdgeInsetsStyle:SEGButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        _commentButton.hidden = YES;
        [_commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.normalBgView);
            make.left.equalTo(self.normalBgView);
            make.height.equalTo(self.normalBgView);
            make.width.mas_equalTo(0).priorityLow();
        }];
        _commentButton.backgroundColor = kColor_TABLE;
 
    }
    return _commentButton;
}

- (SEGAdjustableButton *)praiseButton
{
    if (!_praiseButton) {
        //点赞
        _praiseButton = [[SEGAdjustableButton alloc] init];
        [_praiseButton setTitle:@"点赞" forState:UIControlStateNormal];
        [_praiseButton setTitleColor:kColor_2 forState:UIControlStateNormal];
        [_praiseButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_praise01")] forState:UIControlStateNormal];
        [_praiseButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_praise")] forState:UIControlStateDisabled];
        [_praiseButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_praise")] forState:UIControlStateSelected];
        _praiseButton.titleLabel.font = kFont_10;
        [_praiseButton addTarget:self action:@selector(seg_praiseButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [self.normalBgView addSubview:_praiseButton];
        [_praiseButton layoutButtonWithEdgeInsetsStyle:SEGButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        [_praiseButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.normalBgView);
            make.left.equalTo(self.commentButton.mas_right);
            make.height.equalTo(self.normalBgView);
            make.width.mas_equalTo(0).priorityLow();
        }];
        _praiseButton.backgroundColor = kColor_TABLE;
 
    }
    return _praiseButton;
}

- (SEGAdjustableButton *)publicButton
{
    if (!_publicButton) {
        _publicButton = [[SEGAdjustableButton alloc] init];
        [_publicButton setTitleColor:kColor_W forState:UIControlStateNormal];
        [_publicButton setBackgroundImage:[UIImage imageWithColor:kColor_T] forState:UIControlStateNormal];
        [_publicButton setBackgroundImage:[UIImage imageWithColor:kColor_L2] forState:UIControlStateDisabled];
        _publicButton.titleLabel.font = kFont_16;
        [self.normalBgView addSubview:_publicButton];
        [_publicButton mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.normalBgView);
            make.left.equalTo(self.praiseButton.mas_right);
            make.height.equalTo(self.normalBgView);
            make.width.mas_equalTo(0).priorityLow();
        }];
 
    }
    return _publicButton;
}

- (UIView *)commentBgView
{
    if (!_commentBgView) {
        UIView *commentBgView = [[UIView alloc] init];
        commentBgView.backgroundColor = kColor_W;
        [self addSubview:commentBgView];
        [commentBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self);
            make.top.equalTo(self).offset(0.5);//留出线的位置
            make.height.mas_equalTo(activityToolBarCommentHeight);
         }];
        _commentBgView.hidden = YES;
        _commentBgView = commentBgView;
        
        UIButton *sendButton = [[UIButton alloc] init];
        [sendButton setTitle:@"发送" forState:UIControlStateNormal];
        [sendButton setTitleColor:kColor_T forState:UIControlStateNormal];
        sendButton.titleLabel.font = kFont_16;
        [sendButton addTarget:self action:@selector(seg_sendButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [_commentBgView addSubview:sendButton];
        [sendButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(commentBgView);
            make.right.equalTo(commentBgView);
            make.height.mas_equalTo(commentBgView);
            make.width.mas_equalTo(50);
        }];
        
        UITextView *textView = [[UITextView alloc] init];
        textView.textColor = kColor_1;
        textView.font = kFont_13;
        textView.backgroundColor = kColor_bg;
        textView.tintColor = kColor_T;//光标颜色
        textView.layer.masksToBounds = YES;
        textView.layer.cornerRadius = 2.5;
        textView.textContainerInset = UIEdgeInsetsMake(5, 2, 0, 0);
//        textView.returnKeyType = UIReturnKeySend;
        textView.layer.borderColor = kColor_L2.CGColor;
        textView.layer.borderWidth = 0.5;
        [_commentBgView addSubview:textView];
        [textView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(commentBgView).offset(10);
            make.right.equalTo(sendButton.mas_left);
            make.top.equalTo(commentBgView).offset(10);
            make.bottom.equalTo(commentBgView).offset(-10);
        }];
        self.textView = textView;
        self.textView.delegate = self;

        //提示
        UILabel *describeLabel = [[UILabel alloc] init];
        describeLabel.text = KInputToolBarDefalutDesc;
        describeLabel.font = kFont_13;
        describeLabel.textColor = kColor_3;
        [_commentBgView addSubview:describeLabel];
        [describeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.textView).offset(5);
            make.top.equalTo(self.textView).offset(5);
        }];
        self.describeLabel = describeLabel;
    }
    return _commentBgView;
}
@end
